package com.wingice.system.controller;


import com.wingice.common.web.ErrorCodeInfo;
import com.wingice.system.entity.SysDictionaryItem;
import com.wingice.system.exception.ResultBean;
import com.wingice.system.service.SysDictionaryItemService;
import com.wingice.system.validator.dictionary.SysDictionaryItemValidator;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/sysDictionaryItem")
@Tag(name = "字典项管理")
public class SysDictionaryItemController {

    @Resource
    private SysDictionaryItemService sysDictionaryItemService;

    /**
     * @param sysDictionaryItem 字典项信息
     * @description 新增字典项
     * @author 胡昊
     * @email huhao9277@gmail.com
     * @date 2021/3/5 14:13
     */
    @PostMapping("/insert")
    @Operation(summary = "新增字典项")
    public ResultBean<Boolean> insert(@RequestBody SysDictionaryItem sysDictionaryItem) {
        SysDictionaryItemValidator.insertValidate(sysDictionaryItem);
        return ResultBean.restResult(sysDictionaryItemService.insert(sysDictionaryItem), ErrorCodeInfo.OK);
    }

    /**
     * @param idList 待删除id列表
     * @description 批量删除字典项
     * @author 胡昊
     * @email huhao9277@gmail.com
     * @date 2021/3/5 14:31
     */
    @DeleteMapping("/deleteBatch")
    @Operation(summary = "批量删除字典项")
    public ResultBean<Boolean> deleteBatch(@RequestBody List<String> idList) {
        SysDictionaryItemValidator.deleteValidate(idList);
        return ResultBean.restResult(sysDictionaryItemService.removeByIds(idList), ErrorCodeInfo.NO_CONTENT);
    }

    /**
     * @param sysDictionaryItem 字典项信息
     * @description 更新字典项
     * @author 胡昊
     * @email huhao9277@gmail.com
     * @date 2021/3/5 14:37
     */
    @PatchMapping("/update")
    @Operation(summary = "更新字典项")
    public ResultBean<Boolean> update(@RequestBody SysDictionaryItem sysDictionaryItem) {
        SysDictionaryItemValidator.updateValidate(sysDictionaryItem);
        return ResultBean.restResult(sysDictionaryItemService.update(sysDictionaryItem), ErrorCodeInfo.OK);
    }
}

